var t = getApp();

Page({
    data: {
        active: 0,
        goodsId: 0,
        getUrl: "",
        getJson: {},
        levelList: [],
        groupsList: [],
        isFinished: !1,
        goodsInfo: {},
        widgetsInfo: {},
        discountValues: []
    },
    onLoad: function(t) {
        this.setData({
            goodsId: t.id
        }), this.data.goodsId ? (wx.setNavigationBarTitle({
            title: "商品修改"
        }), this.data.getJson = {
            id: this.data.goodsId
        }, this.data.getDatUrl = "plugin.shop-assistant.frontend.goods.get-detail") : (this.data.getJson = {}, 
        this.data.getDatUrl = "plugin.shop-assistant.frontend.goods.add", wx.setNavigationBarTitle({
            title: "商品发布"
        })), this.getGoodsDetail();
    },
    onReady: function() {},
    releaseGoods: function() {
        var s = this.selectComponent(".base-set"), e = s ? s.validatorData() : null;
        if (e) {
            var a = this.selectComponent(".permissions"), o = a ? a.validatorData() : null;
            if (o) {
                var i = this.selectComponent(".discount"), n = i ? i.validatorData() : null;
                if (n) {
                    var d = e;
                    d.widgets.privilege = o, d.widgets.discount = n, console.log(d), t._isTextEmpty(this.data.goodsId) ? this.saveRequest("plugin.shop-assistant.frontend.goods.create", d) : (d.id = this.data.goodsId, 
                    this.saveRequest("plugin.shop-assistant.frontend.goods.update", d));
                }
            }
        }
    },
    saveRequest: function(s, e) {
        var a = t.getNetAddresss(s);
        t._postNetWork({
            url: a,
            data: e,
            success: function(s) {
                var e = s.data;
                if (t.tips(e.msg), 1 == e.result) {
                    var a = getCurrentPages();
                    a[a.length - 2].getGoodsList(), wx.navigateBack();
                }
            }
        });
    },
    getGoodsDetail: function() {
        var s = this, e = t.getNetAddresss(this.data.getDatUrl);
        t._postNetWork({
            url: e,
            data: this.data.getJson,
            success: function(e) {
                var a = e.data;
                if (1 != a.result) return t.tips(a.msg);
                var o = a.data, i = o.levels, n = o.groups, d = o.goods, g = o.category_menus, l = o.dispatch_templates, r = o.dispatch_types;
                s.setData({
                    isFinished: !0,
                    levelList: i,
                    groupsList: n,
                    goodsInfo: d,
                    categoryMenus: g,
                    dispatchTemplates: l,
                    dispatchTypes: r,
                    widgetsInfo: d ? d.widgets : {},
                    discountValues: i
                });
            }
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    changeTabs: function(t) {
        this.setData({
            active: t.detail.name
        });
    },
    onShareAppMessage: function() {}
});